package com.hunhjy.wx.wxsdk.util;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 
 * @Description: JSON对象转换
 * @author Tim
 * @date 2016年6月24日 下午2:25:46
 *
 */
public final class JsonUtils {

	private JsonUtils() {
	}

	public static String toJson(Object object) {
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.writeValueAsString(object);
		} catch (Exception e) {
			throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
		}
	}

	public static <T> T parse(String jsonString, Class<T> type) {
		try {
			ObjectMapper mapper = new ObjectMapper();
			return mapper.readValue(jsonString, type);
		} catch (Exception e) {
			throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e);
		}
	}

}
